package com.nobug.controller.issue;

import com.nobug.bean.BaseRespVo;
import com.nobug.bean.issue.Issue;
import com.nobug.bean.issue.IssueCreateBO;
import com.nobug.bean.issue.IssueListVO;
import com.nobug.service.issue.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/issue/")
public class IssueController {

    @Autowired
    IssueService service;

    @RequestMapping("list")
    public BaseRespVo<IssueListVO> issueList(Integer page, Integer limit, String sort, String order, String question) {
        if(question == null){
            BaseRespVo<IssueListVO> baseRespVo =  service.queryIssueList(page, limit, sort, order);
            return baseRespVo;
        }
        else {
            Integer offset = (page - 1) * limit;
            BaseRespVo<IssueListVO> baseRespVo = service.queryIssueList(offset, limit, sort, order, question);
            return baseRespVo;
        }
    }

    @RequestMapping("create")
    public BaseRespVo<Issue> issueCreate(@RequestBody IssueCreateBO issueCreateBO){
        BaseRespVo<Issue> baseRespVo = service.issueCreate(issueCreateBO);
        return baseRespVo;
    }


}
